<template>
  <div style="margin-top: 50px;">
    <div style="max-width: 800px;margin: auto">
      <div style="display: inline-block;"><h1>{{ collectName }}</h1></div>
      <div style="display: inline-block;float: right;margin-top: 10px"><el-button type="primary" plain @click="deleteCollect()">删除该收藏夹</el-button></div>
      <el-divider />
      <div v-if="articleList.length !== 0" style="box-shadow: 0 2px 59px rgba(0, 0, 0, .12), 0 0 60px rgba(0, 0, 0, .04);border-radius: 20px;">
        <div style="height: 1px" />
        <div v-for="item in articleList" style="margin: 4%">
          <div style="display: inline-block;">{{ item.articleTitle }}</div>
          <div style="display: inline-block;float: right">
            <el-button type="primary" plain @click="articleTitle(item.articleId)">前往内容页</el-button>
          </div>
          <el-divider />
        </div>
        <div style="height: 1px" />
      </div>
      <div v-else>
        <el-empty description="该收藏夹没有帖子哦~" />
      </div>
    </div>
  </div>
</template>

<script>
import request from "../../../utils/request";
import {gotoNewWindow} from "../../../utils/sameMethod";

export default {
  data() {
    return{
      collectId:'',
      collectName:'',
      articleList:[],
    }
  },
  methods: {
    deleteCollect(){
      this.$confirm('确定删除该删除夹吗？')
          .then(_ => {
            request.delete('/collect/deleteCollect/'+this.collectId).then()
            this.$router.push('/')
            done();
          })
          .catch(_ => {});
    },
    articleTitle(articleId){
      gotoNewWindow(articleId,"content","detail");
    },
    getCollectArticle(){
      request.get('/collect/getCollectArticle/'+this.collectId).then((res =>{
        this.articleList=res.data;
      }))
    }
  },
  created() {
    this.collectId=this.$route.params.collectId;
    this.collectName=this.$route.params.collectName;
  },
  mounted() {
    document.title="收藏夹 - 贴乎";
    this.getCollectArticle();
  }
}
</script>

<style scoped>
</style>